<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/29 0029
 * Time: 16:03
 */

namespace app\home\controller;
use think\Db;


class Activity extends Base
{
        public function index(){
            $data = Db::name('activity')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('main_img,id,title,intro,out_link')->limit(4)->select();
            $this->assign('data',$data);
            $next_data = Db::name('activity')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->page(2,4)->select();
            $type = 1;
            if(!$next_data){
                $type = 2;
            }
            $this->assign('type',$type);
            //场馆基地(顶部导航推荐)
            $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
            $this->assign('data_cg',$data_cg);
            $this->assign('data_seo',getColumnseo(7));
            return $this->fetch();
        }


    public function nr(){

            $id = intval(input('param.id'));
            if($id){
                $data = Db::name('activity')->where('id',$id)->field('content')->find();
                $this->assign('data',$data);
            }

        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        return $this->fetch();
    }


    public function news(){
        $data = Db::name('news')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('main_img,id,title,fb_time,intro,d_zan,click')->limit(6)->select();
        $this->assign('data',$data);
        $next_data = Db::name('news')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->page(2,6)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        $this->assign('type',$type);
        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        $this->assign('data_seo',getColumnseo(8));
        return $this->fetch();
    }

    public function news_nr(){

        $id = intval(input('param.id'));
        if($id){
            $data = Db::name('news')->where('id',$id)->find();
            $this->assign('data',$data);
            addClick($id,'news');
            //上一组
            $upId = Db::name('news')->where('id','<',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id desc')->limit(1)->value('id');
            $this->assign('upId',$upId);
            //下一组
            $downId = Db::name('news')->where('id','>',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id asc')->limit(1)->value('id');
            $this->assign('downId',$downId);
        }
        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        $this->assign('data_seo',getColumnseo(8));
        return $this->fetch();
    }


    public function article(){
        $data = Db::name('article')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('main_img,id,title,fb_time,intro,d_zan,click')->limit(6)->select();
        $this->assign('data',$data);
        $next_data = Db::name('article')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->page(2,6)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        $this->assign('type',$type);
        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        $this->assign('data_seo',getColumnseo(9));
        return $this->fetch();
    }


    public function article_nr(){

        $id = intval(input('param.id'));
        if($id){
            $data = Db::name('article')->where('id',$id)->find();
            $this->assign('data',$data);
            addClick($id,'article');
            //上一组
            $upId = Db::name('article')->where('id','<',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id desc')->limit(1)->value('id');
            $this->assign('upId',$upId);
            //下一组
            $downId = Db::name('article')->where('id','>',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id asc')->limit(1)->value('id');
            $this->assign('downId',$downId);
        }
        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        $this->assign('data_seo',getColumnseo(9));
        return $this->fetch();
    }


    public  function  getmore()
    {
        $where = 'is_del=0 and is_show=1 and sign="pc"';
         $page = intval(input('post.page'));

        $data = Db::name('activity')->where($where)->page($page,4)->select();
        $next_data = Db::name('activity')->where($where)->order('sort desc,id desc')->page($page+1,4)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }


    public  function  getmore_news()
    {
        $where = 'is_del=0 and is_show=1 and sign="pc"';
        $page = intval(input('post.page'));

        $sql = "SELECT `id`,`intro`,`title`,`main_img`,`click`,`d_zan`,FROM_UNIXTIME(fb_time,'%Y/%m/%d') fb_time,
            FROM_UNIXTIME(fb_time,'%Y') nian,FROM_UNIXTIME(fb_time,'%b') yue,FROM_UNIXTIME(fb_time,'%d') ri FROM `dh_news` WHERE ($where) LIMIT $page,4";

        $data=Db::name('news')->query($sql);
        $next_data = Db::name('news')->where($where)->order('sort desc,id desc')->page($page+1,4)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }

    public  function  getmore_article()
    {
        $where = 'is_del=0 and is_show=1 and sign="pc"';
        $page = intval(input('post.page'));
       $sql = "SELECT `id`,`intro`,`title`,`main_img`,`click`,`d_zan`,FROM_UNIXTIME(fb_time,'%Y/%m/%d') fb_time,
            FROM_UNIXTIME(fb_time,'%Y') nian,FROM_UNIXTIME(fb_time,'%b') yue,FROM_UNIXTIME(fb_time,'%d') ri FROM `dh_news` WHERE ($where) LIMIT $page,6";
       $data=Db::name('article')->query($sql);
        $page = $page+1;
       $next_data= Db::name('article')->where($where)->order('sort desc,id desc')->page($page,6)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }

        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }

}